/**
 * @desc		资料编辑效果
 * @author 		Ren Long
 * @date		2013-07-05
 * @return             void
 */
$(document).ready(function() {
    $(".main_table_form").hide();
    $(".main_table_edit").click(function() {
        $(this).parent().parent().next().fadeToggle(300);
    });
});


/**
 * @desc		生成全选效果
 * @author 		Ren Long
 * @date		2013-07-08
 * @return             void
 */
$(document).ready(function() {
    $(".all").click(function() {
//        var a = $(this).closest().html();
//        alert(a);exit;
        if ($(this).is(":checked"))
        {
            $(":checkbox").prop("checked", true);
//            alert("11");
        }
        else
        {
            $(":checkbox").prop("checked", false);
//            alert("22");
        }
    });
});


/**
 * @desc		选择成员效果
 * @author 		Ren Long
 * @date		2013-07-12
 * @return             void
 */
$(document).ready(function() {
    $("#main_team_sub").click(function() {
        var main_team_num = $("[name=main_team_num]").val();
        if (main_team_num < 1)
        {
            $("#main_team_sub").next("span").text("请输入数值").show(300);
            return false;
        }
        else if (!($('.main_table_sel:checkbox').is(":checked")))
        {
            $("#main_team_sub").next("span").text("请选择成员").show(300);
            return false;
        }
        else
        {
            $("#main_team_sub").next("span").hide(300);
            $("#main_left form").append("<p style=\"text-align:right;color:red;\">" + '第' + main_team_num + '组' + "</p>");
            $('.main_table_sel:checkbox:checked').each(function()
            {
                $(this).parent().parent().hide(300);
                $(this).removeAttr("checked");
                var id = $(this).val();
                var html = '<input type="hidden" id="s_' + main_team_num + id + '" name="group[' + main_team_num + '][]" value="' + id + '" />';
                $("#main_left form").append($(this).parent().next().html()).append(html);
            });
        }

        $("#main_left").find('p').bind(
        {
            dblclick:function()
            {
                $(this).remove();
            },
            mouseover:function()
            {
                $(this).css({"background-color":"#A7C942",
                             "cursor":"pointer"});
            },
            mouseout:function()
            {
                $(this).css("background-color","#FFFFFF");
            }
        });

        $("#main_left").find('form div').bind({
            dblclick:function()
            {
                $(this).remove();
                var a = $(this).data('id');
                $("#s_" + main_team_num + a).remove();
                $('#member_' + a).show(300);
            },
            mouseover:function()
            {
                $(this).css({"background-color":"#A7C942",
                             "cursor":"pointer"});
            },
            mouseout:function()
            {
                $(this).css("background-color","#FFFFFF");
            }
        });
    });
});


/**
 * @desc		生成表单判断
 * @author 		Ren Long
 * @date		2013-07-12
 * @return             boolean
 */
$(document).ready(function() {
    $("#main_left_form").submit(function() {
        var data = $(this).find("div").html();
        var title = $("[name=main_left_title]").val();
        if (data == null)
        {
            $("[name=main_left_sub]").next("span").text("没有东西呀").show(300);
            return false;
        }
        else if (title == "")
        {
            if (confirm('确实不需要标题吗？'))
            {
                $(this).next("span").text('');
                return true;
            }
            else
            {
                return false;
            }
        }
    });
});


/**
 * @desc		删除成员
 * @author 		Ren Long
 * @date		2013-07-12
 * @return             void
 */
$(document).ready(function() {
    $(".del").click(function() {
        if (confirm("亲爱滴~确实要毙掉这娃子吗？"))
        {
            var uid = $(this).parent().parent().children().find("input").val();
            var user = $(this).parent().parent().children().find("div").text();
            $.get("index.php?app=del", {uid: uid}, function(data) {
                if (data == true)
                {
                    alert('娘子,' + user + '已随风而去鸟~');
                }
                else
                {
                    alert("出错了，快联系你老公吧！");
                }
            });
        }
    });
});